<template>
	<view class="order">
		<view class="priceBox">
			<view class="price bold">￥<text>{{money}}</text></view>
			<view class="font12 color999">购买择校报告</view>
		</view>
		<view class="" v-if="showPay">
			<view class="font14 color999">支付方式</view>
			<view class="payWay">
				<view class="flex alignCenter" v-for="(item,index) in payArr" :key="index" @click="choosePay(index)">
					<image :src="item.icon" mode="widthFix"></image>
					<view class="chooseBox flex alignCenter">
						<view class="payName font16">{{item.title}}</view>
						<label class="radio">
							<radio class="radiuBox" :value="payVal" :checked="payVal==index+1" />
						</label>
					</view>
				</view>
			</view>
		</view>
		<view class="fixedBottomBtn" @click="sure">确认交易</view>
	</view>
</template>

<script>
	import {
		getOrderAndPay
	} from "@/utils/common.js"
	import {
		entrustFoundPerson
	} from "@/api/lookFor.js"
	import {
		getPDFList
	} from '@/api/toolbox.js'
	export default {
		data() {
			return {
				payVal: '1',
				payArr: [{
					title: '微信支付',
					icon: '/static/image/icons/wechat.png'
				}, ],
				money: 0,
				// 支付的由头  2查看最佳答案；3赏金；4、活动，5、查看专业详情支付，6、发布找人，7、购买择校报告 8、调剂信息单条支付 9、调剂信息全部支付
				type: 2,
				// 查看答案付费就是答案详情id
				nextId: '',
				// 回答详情需要传入提问标题
				title: '',
				optionQuery: '',
				showPay: true,
				popupType: 1, //1、发布成功弹窗，2、读取通讯录弹窗 
				findUserItem: {}, //委托找人学长学姐数据
				school: {},
				adJustParam: {}, //调剂支付传参信息
			};
		},
		onLoad(option) {
			console.log('option: ',option);
			this.money = option?.price || 0;
			this.type = 7;
			// ios苹果内支付
			// #ifdef APP-PLUS
			if (uni.getStorageSync('systemInfo').platform == 'ios') {
				this.showPay = false
			}
			// #endif
			this.school = uni.getStorageSync('school')
		},
		methods: {
			// 选择支付方式
			choosePay(idx) {
				this.payVal = (Number(idx) + 1).toString()
			},
			sure() {
				if (this.showPay) {
					let param = {
						orderType: this.type,
						payWay: this.payVal, //1微信；2支付宝；3第三方
						id: 14
					}
					// #ifdef MP
					param.payProduct = 1 //1小程序；2App
					// #endif
					// #ifdef APP-PLUS
					param.payProduct = 2
					// #endif
					getOrderAndPay(param).then((res) => {
						let payOrderId = res.data.payOrderId;
						if(res.code == 100000){
							uni.redirectTo({
								url:'/pages/toolbox/chooseSchool/placeOrder?payOrderId='+payOrderId
							})
						}
					}).finally(() => {
						uni.hideLoading()
					})
				} else {
					// ios 苹果应用内支付
					uni.getProvider({
						service: 'payment',
						success: (res) => {
							console.error('应用内支付', res)
							const iapChannel = res.providers.find((channel) => {
								return (channel.id === 'appleiap')
							})

							// 如果 iapChannel 为 null，说明当前包没有包含iap支付模块。注意：HBuilder基座不包含 iap 通道
						}
					});
				}
			},
		}
	}
</script>
<style lang="scss">
	page {
		background: $pageBgColor;
	}
</style>
<style lang="scss" scoped>
	::v-deep .radiuBox .uni-radio-input-checked {
		background-color: $colorMain !important;
		border-color: $colorMain !important;
	}

	::v-deep .radiuBox .uni-radio-input {
		transform: scale(0.7);
	}

	.order {
		padding: 100rpx 30rpx 0;
		box-sizing: border-box;
	}

	.priceBox {
		text-align: center;
		margin: 0 0 100rpx;

		.price {
			text {
				font-size: 70rpx;
			}

		}
	}

	.payWay {
		background: #fff;
		padding: 0 30rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
		margin: 30rpx 0 0;

		&>view:last-child {
			.chooseBox {
				border: none;
			}
		}

		.payName {
			flex: 1;
		}

		image {
			width: 60rpx;
			height: 60rpx;
			margin-right: 20rpx;
			flex-shrink: 0;
		}

		.chooseBox {
			flex: 1;
			padding: 50rpx 0;
			border-bottom: 1px solid $bordercolor;
		}
	}

	.popup-box {
		.box1 {
			width: 540rpx;
			height: 548rpx;
			background: #fff;
			border-radius: 28rpx;
			text-align: center;
			margin: 0 auto;
			line-height: 1em;
			position: relative;

			image {
				width: 152rpx;
				height: 146rpx;
				margin-top: 24rpx;
			}

			.title {
				margin-top: 12rpx;
			}

			.tips {
				line-height: 40rpx;
				margin-top: 40rpx;
				margin-bottom: 80rpx;
			}

			.btn {
				width: 310rpx;
				height: 80rpx;
				background: $colorMain;
				border-radius: 80rpx;
				justify-content: center;
				margin: auto;
			}

			.clear-icon {
				position: absolute;
				margin-top: 160rpx;
				margin-left: -46rpx;
			}
		}

		.box2 {
			width: 480rpx;
			height: 624rpx;
			background: #fff;
			border-radius: 28rpx;
			text-align: center;
			margin: 0 auto;
			line-height: 1em;
			position: relative;

			image {
				width: 256rpx;
				height: 132rpx;
				margin: 30rpx 0 10rpx;
			}

			.tips {
				color: #1E1E1E;
				line-height: 40rpx;
			}

			.tips:first-child {
				padding-top: 40rpx;
			}

			.btn {
				width: 310rpx;
				height: 70rpx;
				background: #fff;
				border-radius: 80rpx;
				justify-content: center;
				border: 1px solid rgba(247, 221, 94, 1);
				margin: 44rpx auto 20rpx;
			}

			.clear-icon {
				position: absolute;
				margin-top: 92rpx;
				margin-left: -46rpx;
			}
		}

	}
</style>